{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/jeffheaton/t81_558_deep_learning/blob/master/manual_setup.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# T81-558: Applications of Deep Neural Networks\n",
    "**Manual Python Setup**\n",
    "* Instructor: [Jeff Heaton](https://sites.wustl.edu/jeffheaton/), McKelvey School of Engineering, [Washington University in St. Louis](https://engineering.wustl.edu/Programs/Pages/default.aspx)\n",
    "* For more information visit the [class website](https://sites.wustl.edu/jeffheaton/t81-558/)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Software Installation\n",
    "This class is technically oriented.  A successful student needs to be able to compile and execute Python code that makes use of TensorFlow for deep learning. There are two options for you to accomplish this:\n",
    "\n",
    "* Install Python, TensorFlow and some IDE (Jupyter, TensorFlow, and others)\n",
    "* Use Google CoLab in the cloud\n",
    "\n",
    "## Installing Python and TensorFlow\n",
    "\n",
    "It is possible to install and run Python/TensorFlow entirely from your computer.  Google provides TensorFlow for Windows, Mac, and Linux.  Previously, TensorFlow did not support Windows.  However, as of December 2016, TensorFlow supports Windows for both CPU and GPU operation.\n",
    "\n",
    "The first step is to install Python 3.7.  As of August 2019, this is the latest version of Python 3.  I recommend using the Miniconda (Anaconda) release of Python, as it already includes many of the data science related packages that are needed by this class.  Anaconda directly supports Windows, Mac, and Linux.  Miniconda is the minimal set of features from the extensive Anaconda Python distribution.  Download Miniconda from the following URL:\n",
    "\n",
    "* [Miniconda](https://docs.conda.io/en/latest/miniconda.html)\n",
    "\n",
    "# Dealing with TensorFlow incompatibility with Python 3.7\n",
    "\n",
    "*Note: I will remove this section once all needed libraries add support for Python 3.7.\n",
    "\n",
    "**VERY IMPORTANT** Once Miniconda has been downloaded you must create a Python 3.6 environment.  Not all TensorFlow 2.0 packages currently (as of August 2019) support Python 3.7.  This is not unusual, usually you will need to stay one version back from the latest Python to maximize compatibility with common machine learning packages. So you must execute the following commands:\n",
    "\n",
    "```\n",
    "conda create -y --name tensorflow python=3.6\n",
    "```\n",
    "\n",
    "To enter this environment, you must use the following command (**for Windows**), this command must be done every time you open a new Anaconda/Miniconda terminal window:\n",
    "\n",
    "```\n",
    "activate tensorflow\n",
    "```\n",
    "\n",
    "\n",
    "For **Mac**, do this:\n",
    "\n",
    "```\n",
    "source activate tensorflow\n",
    "```\n",
    "\n",
    "# Installing Jupyter\n",
    "\n",
    "it is easy to install Jupyter notebooks with the following command:\n",
    "\n",
    "```\n",
    "conda install -y jupyter\n",
    "```\n",
    "\n",
    "Once Jupyter is installed, it is started with the following command:\n",
    "\n",
    "```\n",
    "jupyter notebook\n",
    "```\n",
    "\n",
    "The following packages are needed for this course:\n",
    "\n",
    "```\n",
    "conda install -y scipy\n",
    "pip install --exists-action i --upgrade sklearn\n",
    "pip install --exists-action i --upgrade pandas\n",
    "pip install --exists-action i --upgrade pandas-datareader\n",
    "pip install --exists-action i --upgrade matplotlib\n",
    "pip install --exists-action i --upgrade pillow\n",
    "pip install --exists-action i --upgrade tqdm\n",
    "pip install --exists-action i --upgrade requests\n",
    "pip install --exists-action i --upgrade h5py\n",
    "pip install --exists-action i --upgrade pyyaml\n",
    "pip install --exists-action i --upgrade tensorflow_hub\n",
    "pip install --exists-action i --upgrade bayesian-optimization\n",
    "pip install --exists-action i --upgrade spacy\n",
    "pip install --exists-action i --upgrade gensim\n",
    "pip install --exists-action i --upgrade flask\n",
    "pip install --exists-action i --upgrade boto3\n",
    "pip install --exists-action i --upgrade gym\n",
    "pip install --exists-action i --upgrade tensorflow==2.0.0-beta1\n",
    "pip install --exists-action i --upgrade keras-rl2 --user\n",
    "conda update -y --all\n",
    "```\n",
    "\n",
    "Notice that I am installing as specific version of TensorFlow.  As of the current semester, this is the latest version of TensorFlow.  It is very likely that Google will upgrade this during this semester. The newer version may have some incompatibilities, so it is important that we start with this version and end with the same.\n",
    "\n",
    "You should also link your new **tensorflow** environment to Jupyter so that you can choose it as a Kernal.  Always make sure to run your Jupyter notebooks from your 3.6 kernel.  This is demonstrated in the video.\n",
    "\n",
    "```\n",
    "python -m ipykernel install --user --name tensorflow --display-name \"Python 3.6 (tensorflow)\"\n",
    "```\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensor Flow Version: 2.0.0-beta1\n",
      "Keras Version: 2.2.4-tf\n",
      "\n",
      "Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 13:42:17) \n",
      "[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]\n",
      "Pandas 0.25.0\n",
      "Scikit-Learn 0.21.3\n",
      "GPU is NOT AVAILABLE\n"
     ]
    }
   ],
   "source": [
    "# What version of Python do you have?\n",
    "import sys\n",
    "\n",
    "import tensorflow.keras\n",
    "import pandas as pd\n",
    "import sklearn as sk\n",
    "import tensorflow as tf\n",
    "\n",
    "print(f\"Tensor Flow Version: {tf.__version__}\")\n",
    "print(f\"Keras Version: {tensorflow.keras.__version__}\")\n",
    "print()\n",
    "print(f\"Python {sys.version}\")\n",
    "print(f\"Pandas {pd.__version__}\")\n",
    "print(f\"Scikit-Learn {sk.__version__}\")\n",
    "print(\"GPU is\", \"available\" if tf.test.is_gpu_available() else \"NOT AVAILABLE\")"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3.7 (tensorflow)",
   "language": "python",
   "name": "tensorflow"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
